<?php
namespace app\index\controller;

use think\Controller;
use think\View;
use Jssdk\JSSDK;

class Page extends Common {
    /**
     * 获取单页数据
     * @return \think\response\View
     */
    public function article() {
        if (is_weixin()) {
            $jssdk = new JSSDK(config('wechat.appid'), config('wechat.appsecret'));
            $signPackage = $jssdk->getSignPackage();
            $this->assign('signPackage', $signPackage);
        }

        $cid = input('param.cid', 0);
        $id = input('param.id', 0);

        $list = model('page_article')->where('page_category_id', $cid)->select();
        if ($id > 0) {
            $data = model('page_article')->where('id', $id)->where('page_category_id', $cid)->find();
        } else {
            $data = model('page_article')->where('page_category_id', $cid)->order('id desc')->find();
        }

        // 修改文章点击数
        $hits = rand(1, 3);
        model('page_article')->where(['id' => $data->id])->setInc('hits', $hits);

        $this->assign('list', $list);
        $this->assign('data', $data);
        return view();
    }

}
